<!--
 * @description:
 * @author: cuicui
 * @Date: 2023-11-28 19:51:46
 * @LastEditTime: 2023-11-30 11:47:52
 * @LastEditors: cuicui
-->
<template>
  <a-modal
    title='预览操作票'
    :width='940'
    :visible='previewVisible'
    :confirmLoading='previewloading'
    :footer='null'
    @cancel="() => { $emit('cancel') }"
  >
    <a-spin :spinning='previewloading'>
      <hydrogen :model='model' />
    </a-spin>
  </a-modal>
</template>

<script>
import pick from 'lodash.pick'
import { Hydrogen } from '@/business-components/operation-ticket/index'
import { STable } from '@/components'

// 表单字段
const fields = ['sys-type', 'equipment_type', 'point_type']
const columns = [
  {
    title: '序号',
    scopedSlots: { customRender: 'serial' }
  },
  {
    title: '名称',
    dataIndex: 'description',
    scopedSlots: { customRender: 'description' }
  },
  {
    title: '描述',
    dataIndex: 'id1'
  },
  {
    title: '操作',
    dataIndex: 'action',
    scopedSlots: { customRender: 'action' }
  }
]
export default {
  components: { STable, Hydrogen },
  props: {
    previewVisible: {
      type: Boolean,
      required: true
    },
    previewloading: {
      type: Boolean,
      default: () => false
    },
    model: {
      type: Object,
      default: () => null
    }
  },
  data() {
    this.columns = columns
    this.formLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 3 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 21 }
      }
    }
    return {
      form: this.$form.createForm(this),
      queryParam: {},
      loadData: ''
    }
  },
  created() {
    // 防止表单未注册
    fields.forEach(v => this.form.getFieldDecorator(v))

    // 当 model 发生改变时，为表单设置值
    this.$watch('model', () => {
      console.log(this.model, 'this.model')
      this.model && this.form.setFieldsValue(pick(this.model, fields))
    })
  }
}
</script>
